<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container" >
      <el-input
        v-model="infoForm.userName"
        clearable
        class="filter-item"
        style="width: 200px;"
        placeholder="请输入用户名"
      />
      <el-input
        v-model="infoForm.roleName"
        clearable
        class="filter-item"
        style="width: 200px;"
        placeholder="请输入角色名"
      />
      <el-input
        v-model="infoForm.ipAdress"
        clearable
        class="filter-item"
        style="width: 200px;"
        placeholder="请输入ip地址"
      />
      <el-date-picker
        v-model="infoForm.loginTime"
        type="date"
        class="filter-item"
        style="width: 200px;"
        placeholder="选择日期">
      </el-date-picker>

      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="queryLog(1)"
      >查找</el-button>
    </div>

    <!-- 查询结果 -->
    <div >
      <el-table
        v-loading="listLoading"
        :data="list"
        size="small"
        element-loading-text="正在查询中。。。"
        :height="tabHeight"
        border
        fit
        highlight-current-row
      >
        <el-table-column align="center" width="200px" label="用户姓名" prop="userName" sortable />
        <el-table-column align="center" width="200px" label="用户角色" prop="roleName"/>
        <el-table-column align="center" width="200px" label="登录时间" prop="loginTime"/>
        <el-table-column align="center" width="200px" label="ip地址" prop="ipAddress"/>
      </el-table>
    </div>

    <!-- 分页角标-->
    <div class="fypage">
      <el-pagination
        v-show="total>0"
        :total="total"
        :page="pageNum"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>

  </div>
</template>

<script>
    export default {
        name: "loginLog",
        data(){
            return{
                infoForm: {
                    userName: '',
                    roleName: '',
                    ipAddress: '',
                    loginTime: '',
                },
                total: 1,
                pageNum: 1,
                pageSize: 10,
                orderBy: '',
                sort: '',
                list:[],
                listLoading: false,
                tabHeight: 540,

            }
        },
        created() {
            this.queryLog(1)
        },
        methods: {

            handleSizeChange(size){
                this.queryLog()
            },
            handleCurrentChange(current){
                this.queryLog(current)
            },

            //当前页数，排序字段，排序方式
            queryLog(page,order,sortord){
                const self = this
                self.listLoading = true
                self.pageNum = page
                console.log(this.pageNum)
                self.orderBy = order
                self.sort = sortord
                let data = {
                    'userName': self.infoForm.userName || null, //用户名
                    'roleName': self.infoForm.roleName || null, //用户角色
                    'ipAddress': self.infoForm.ipAddress || null, //ip地址
                    'loginTime': self.infoForm.loginTime || null, //登录时间

                    'orderBy': self.orderBy || null, //排序字段
                    'pageNum': self.pageNum || 1, //当前页数
                    'pageSize': self.pageSize || 10, //每页展示条数
                    'sort': self.sort || null, //排序方式
                }
                self.$axios.post('/manage/tool/log',data).then(res =>{
                    try {
                        self.list = res.data.data
                        self.total = res.data.total
                        self.listLoading = false
                    }catch(err){
                        self.listLoading = false
                        self.$message.error(res.data.msg)
                    }
                }).catch(err => {
                    self.$message.error("查询出错！！！！！")
                    self.listLoading = false
                })
            },
        }
    }
</script>

<style scoped>

</style>
